package cn.jbit.commodity.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.jbit.commodity.dao.CommodityDao;
import cn.jbit.pojo.commodity;
import cn.jbit.pojo.commodity_details;
import cn.jbit.pojo.commodity_type;

@Service
@Transactional
public class CommodityServiceImpl implements CommodityService {

	@Resource
	private CommodityDao commodityDao;
	/**
	 * 名称模糊查询
	 */
	@Override
	public PageInfo<commodity> fuzzyQueryOfCommodityNames(String commodity_name, Integer pageNum, Integer userId,
			Integer commodity_type_id,Integer commodity_state,Integer commodity_id) {
		try {
			// 执行分页查询
			Page<commodity> pagesCommodity = PageHelper.startPage(pageNum, 10);
			// 必须执行
			List<commodity> commlist= commodityDao.fuzzyQueryOfCommodityNames(commodity_name, userId, commodity_type_id,commodity_state,commodity_id);
			
			PageInfo<commodity> pageInfo = new PageInfo<commodity>(commlist);
			
			
			return pageInfo;
		} catch (Exception e) {
			System.out.println("查询商品模块出错 了=================");
			return null;
		}

		
	}

	/**
	 * 查询所有商品类型表信息
	 * 
	 */
	@Override
	public List<commodity_type> queryCommodityType() {
		try {
			return commodityDao.queryCommodityType();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("查询商品模块出错 了=================");
			return null;
		}
		
	}

	@Override
	public void modifyCommodity(commodity comm) {
		try {
			commodityDao.modifyCommodity(comm);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("修改商品模块出错 了=================");
		}
	}

	@Override
	public void addCommodity(commodity commodity){
		try {
			commodityDao.addCommodity(commodity);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("添加商品模块出错 了=================");
		}
	}

	@Override
	public void addCommodityType(String commoditytype_name) {
		// TODO Auto-generated method stub
		commodityDao.addCommodityType(commoditytype_name);
	}

	@Override
	public void modifyState(Integer id, Integer state) {
		commodityDao.modifyState(id, state);
		
	}

	@Override
	public commodity queryDetails(Integer id) {
		// TODO Auto-generated method stub
		return commodityDao.queryDetails(id);
	}

	@Override
	public void addDetailsImg(commodity_details comm_details) {
		commodityDao.addDetailsImg(comm_details);
		
	}


}
